<template>
  <div class="column">
    <router-view/>
    <div class="panelAll" >
      <div class="boxb"><h2>重点工业企业产值完成情况</h2></div>
      <!--
      v-table prop:model => 0:默认 1:头 2:只取有id的
      -->
      <v-table :model="2" :header="this.header1" :body="this.body1" :popUpFrame='true'/>
      <v-table :model="2" :header="this.header2" :body="this.body2" :popUpFrame='true'/>
      <v-table :model="0" :header="this.header3" :body="this.body3" :popUpFrame='true' :flag-id="true"/>
      <div class="panelSmLonggy-foot"></div>
      <pop-up-frame></pop-up-frame>
    </div>
  </div>
</template>

<script>
import popUpFrame from "@/components/pop-up-frame"
export default {
  name: "gy9",
  components:{
    popUpFrame
  },
  computed: {
    year() {
      return this.$store.year
    },
    month() {
      return this.$store.month
    }
  },
  watch: {
    '$store.time': {
      immediate: true,
      deep: true,
      handler(v) {
        this.getdata1()
        this.getdata2()
        this.getdata3()
        this.testa()
      }
    }
  },
  methods: {
    getdata1() {
      this.a = 0;
      this.header1[2].name = this.month+''+'月当月(万元)'
      this.header1[3].name = this.month+''+'月止累计(万元)'
      // this.$util.http.get('/excel/08/info/2023/1/0').then(res=>{
      this.$util.http.get('/excel/08/info/'+this.year+'/'+this.month+'/0').then(res=>{
        for(var i = 0; i < res.data.length; i++){
          res.data[i].id = i+1;
          for(var j = 0; j<res.data[i].children.length;j++){
            res.data[i].children[j].id = null
          }
        }
        this.a = 1;
        this.body1 = this.solveGroup(res.data)
      })
    },

    getdata2() {
      this.a = 0;
      this.header2[2].name = this.month+''+'月当月(万元)'
      this.header2[3].name = this.month+''+'月止累计(万元)'
      this.$util.http.get('/excel/08/info/'+this.year+'/'+this.month+'/1').then(res=>{
        if (!res.data) return
        for(var i = 0; i < res.data.length; i++){
          res.data[i].id = i+1;
          for(var j = 0; j<res.data[i].children.length;j++){
            res.data[i].children[j].id = null
          }
        }
        this.a = 1;
        this.body2 = this.solveGroup(res.data)
      })
    },

    getdata3() {
      this.a = 0;
      this.header3[1].name = this.month+''+'月当月(万元)'
      this.header3[2].name = this.month+''+'月止累计(万元)'
      this.$util.http.get('/excel/08/keyInfo/'+this.year+'/'+this.month).then(res=>{
        for(var i = 0; i < res.data.length; i++){
          if(res.data[i].number == 0){
            res.data[i].number = null;
          }
          // res.data[i].currentMonth = res.data[i].currentMonth.toFixed(0);
          // res.data[i].currentAccumulate = res.data[i].currentAccumulate.toFixed(0);
          // res.data[i].monthOnMothAccumulate = res.data[i].monthOnMothAccumulate.toFixed(1);
        }
        this.a = 1;
        this.body3 = res.data
      })
    },

    testa(){
      if(this.a == 0){
        this.body1=[]
        this.body2=[]
        this.body3=[]
      }
    },

    solveGroup(data) {
      let solvedData = []
      for (let i in data) {
        solvedData.push(data[i])
        solvedData.push(...data[i].children)
      }
      return solvedData
    }

  },

  data() {
    return {
      a:0,

      header1: [
          {
            name: "序号",
            value: "id",
          },
        {
          name: "企业名称",
          value: "name",
        },
        {
          name: "9月当月(万元)",
          value: "gyczCurrentmonth",
        },
        {
          name: "9月止累计(万元)",
          value: "gyczCurrentaccumulate",
        },
        {
          name: "累计同比±%",
          value: "gyczMonthonmonth2",
        },
      ],


      body1: [],

      header2: [
        {
          name: "序号",
          value: "id",
        },
        {
          name: "企业名称",
          value: "name",
        },
        {
          name: "9月当月(万元)",
          value: "gyczCurrentmonth",
        },
        {
          name: "9月止累计(万元)",
          value: "gyczCurrentaccumulate",
        },
        {
          name: "累计同比±%",
          value: "gyczMonthonmonth2",
        },
      ],


      body2: [],

      header3: [
        {
          name: "企业名称",
          value: "name",
        },
        {
          name: "9月当月(万元)",
          value: "gyczCurrentmonth",
        },
        {
          name: "9月止累计(万元)",
          value: "gyczCurrentaccumulate",
        },
        {
          name: "累计同比±%",
          value: "gyczMonthonmonth2",
        },
      ],


      body3: [],
    }
  }
}
</script>

<style scoped>

</style>